# -*- coding: utf-8 -*-
import json

from devicetest.api import Asserts
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import ControlCenter


class PreTest_RK3568_Basic_Systemui_1200(TestCase, ControlCenter):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 进入桌面，右上角下划进入控制中心，点击控制中心右上角编辑按钮，长按拖动应用位置
    # 预期结果：
    # 进入快捷开关编辑页面，拖动图标生效，点击完成，返回至控制中心显示无异常/点击重置并确认重置，返回至控制中心显示无异常

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1、进入桌面，右上角下划进入控制中心，点击控制中心右上角编辑按钮，长按拖动应用位置')
        CommonOH.swipe(self.Phone1, **self.pull_down)
        CommonOH.wait(self.Phone1, 1)
        screenshot_switch0 = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='截屏'))['bounds']
        airplane_mode_switch0 = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='飞行模式'))['bounds']

        CommonOH.click(self.Phone1, **self.edit_btn)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.drag(self.Phone1, sx=140, sy=485, ex=140, ey=325)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '完成')
        CommonOH.wait(self.Phone1, 0.5)
        Step('预期结果1、进入快捷开关编辑页面，拖动图标生效，点击完成，返回至控制中心显示无异常/点击重置并确认重置，返回至控制中心显示无异常')
        screenshot_switch1 = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='截屏'))['bounds']
        airplane_mode_switch1 = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='飞行模式'))['bounds']
        Asserts.assert_greater(screenshot_switch1['leftX'], screenshot_switch0['leftX'])
        Asserts.assert_equal(screenshot_switch1['topY'], screenshot_switch0['topY'])
        Asserts.assert_equal(airplane_mode_switch1['leftX'], airplane_mode_switch0['leftX'])
        Asserts.assert_greater(airplane_mode_switch0['topY'], airplane_mode_switch1['topY'])

    def teardown(self):
        common_teardown(self.Phone1)
        Step('收尾2：重置控制中心快捷开关顺序')
        CommonOH.swipe(self.Phone1, **self.pull_down)
        CommonOH.click(self.Phone1, **self.edit_btn)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '重置')
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '重置', index=1)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '完成')
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.swipe(self.Phone1, **self.pull_up)